package wan.moneybook.handler;

import java.util.Calendar;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import wan.moneybook.bean.Account;
import wan.moneybook.bean.Row;
import wan.moneybook.sql.SqlMapper;

import com.ibatis.sqlmap.client.SqlMapClient;

public class TabsHandler implements Handler {

	@SuppressWarnings("unchecked")
	@Override
	public String process(HttpServletRequest request,
			HttpServletResponse response) throws Throwable {

		Row bean = new Row();
		bean.setId(((Account)request.getSession().getAttribute("account")).getId());
		bean.setTab(Integer.parseInt(request.getParameter("tab")));

		if (request.getParameter("date") != null) {
			bean.setDate(Long.parseLong(request.getParameter("date")));
		} else {
			bean.setDate(Calendar.getInstance().getTime());
			request.setAttribute("date", bean.getDate());
		}

		SqlMapClient sqlMap = SqlMapper.getInstance();
		List list = sqlMap.queryForList("selectRecord",bean);
		request.setAttribute("list", list);
		return "/WEB-INF/jspf/contents.jsp";
	}
}
